<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../lib/layui/css/layui.css">
    <link rel="stylesheet" href="../../css/oksub.css">
</head>
<body style="margin: 10px 10px 0 10px">
<!--数据表格-->
<div class="list-con">
    <table class="layui-hide" id="tableId" lay-filter="tableId"></table>
</div>

<script src="../../lib/layui/layui.js"></script>
<script src="../../js/jquery.min.js"></script>
<script src="../../js/application.js"></script>
<script>
    var processId=GetQueryString("processId");
    layui.use(["table", 'laydate', 'form','layer'], function () {
        let $ = layui.jquery;
        let table = layui.table;
        let form = layui.form;
        let layer=layui.layer;
        let laydate = layui.laydate;

        let articleTable = table.render({
            elem: "#tableId",
            url: mainUri+"/resources/select",
            where: {operNoteId:processId},
            cols: [[
                {field: "resourcesId", title: "资源Id", hide: true},
                {field: "resourcesName", title: "附件名称"},
                {field: "uploadTime", title: "上传时间"},
                {fixed: 'right', width: 165, align:'center', toolbar: '#barDemo'}
            ]]
        });

        function fileDonw(data){
            window.open(mainUri + "/fileDown/downloadFileByResId?resourcesId=" + data.resourcesId);
        }

        function fileDelete(data){
            console.log(data)
            layer.confirm('确定删除此附件？', {
                btn: ['确定', '取消']//按钮
                , title: ''
            }, function (index) {
                layer.close(index);
                showloading(true)
                $.ajax({
                    url: mainUri + "/fileDown/deleteById",
                    data: {
                        resourcesId: data.resourcesId,
                        resourcesUrl:data.resourcesUrl
                    },
                    type: "Post",
                    dataType: "json",
                    success: function (data) {
                        showloading(false)
                        if (data.code == 0) {
                            layer.msg('删除成功', {
                                icon: 1,
                                time: 1500 //2秒关闭（如果不配置，默认是3秒）
                            }, function () {
                                articleTable.reload();
                            });
                        }
                    },
                    error: function (e) {
                        showloading(false)
                        console.log(e)
                        layer.alert('删除失败,请重试');
                    }
                })
            });
        }

        table.on("tool(tableId)", function (obj) {
            let data = obj.data;
            switch (obj.event) {
                case "download":
                    fileDonw(data)
                    break;
                case "delete":
                    fileDelete(data)
                    break;
            }
        });
    })
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="download">下载</a>
    <a class="layui-btn layui-btn-xs  layui-btn-danger" lay-event="delete">删除</a>
</script>
</body>
</html>